package com.example.design.utils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.concurrent.ThreadLocalRandom;

/**
 * 文件工具类
 */
public class FileUtils {

    public static String getExtension(String fileName) {
        int idx = fileName.lastIndexOf(".");
        return (idx > 0 && idx < fileName.length() - 1)
                ? fileName.substring(idx + 1)
                : "";
    }

    public static String generateBatchId() {
        String time = LocalDateTime.now()
                .format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
        String random = String.format("%04d", ThreadLocalRandom.current().nextInt(10000));
        return time + random;
    }
}
